/* @(#)FmmCompletableNodeImpl.java
** 
** Copyright (C) 2012 by Steven D. Stamps
**
**             Trademarks & Copyrights
** Flywheel Management Science(TM), Flywheel Management Model(TM),
** Flywheel Story Editor(TM) and FlywheelMS(TM) are exclusive trademarks
** of Steven D. Stamps and may only be used freely for the purpose of
** identifying the unforked version of this software.  Subsequent forks
** may not use these trademarks.  All other rights are reserved.
**
** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
** are also exclusive trademarks of Steven D. Stamps.  These may be used
** freely within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** gConGUI (game Controller Graphical User Interface) is an exclusive
** trademark of Steven D. Stamps.  This trademark may be used freely
** within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** Trademark information is available at
** <http://www.flywheelms.com/trademarks>
**
** Flywheel Management Science(TM) is a copyrighted body of management
** metaphors, governance processes, and leadership techniques that is
** owned by Steven D. Stamps.  These copyrighted materials may be freely
** used, without alteration, by the community (users and developers)
** surrounding this GPL3-licensed software.  Additional copyright
** information is available at <http://www.flywheelms.org/copyrights>
**
**              GPL3 Software License
** This program is free software: you can use it, redistribute it and/or
** modify it under the terms of the GNU General Public License, version 3,
** as published by the Free Software Foundation. This program is distributed
** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details. You should
** have received a copy of the GNU General Public License, in a file named
** COPYING, along with this program.  If you cannot find your copy, see
** <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.flywheelms.library.fmm.node.impl.completable;

import com.flywheelms.library.deckangl.enumerator.WorkStateColor;
import com.flywheelms.library.deckangl.glyph.DecKanGlDictionary;
import com.flywheelms.library.deckangl.glyph.NounWorkStatus;
import com.flywheelms.library.fmm.node.FmmNodeInfo;
import com.flywheelms.library.fmm.node.NodeId;
import com.flywheelms.library.fmm.node.impl.enumerator.CompletableWorkState;
import com.flywheelms.library.fmm.node.impl.enumerator.CompletionCommitmentType;
import com.flywheelms.library.fmm.node.impl.governable.FmmGovernableNodeImpl;
import com.flywheelms.library.fmm.node.interfaces.horizontal.FmmNodeCompletion;

public abstract class FmmCompletableNodeImpl extends FmmGovernableNodeImpl 
		implements FmmNodeCompletion, FmmNodeInfo {
	
	private static final long serialVersionUID = 7670030679294983810L;
	private boolean autocompletable;
	private int sequence;
	private String workStateCode = CompletableWorkState.NOT_STARTED.getName();
	private CompletableWorkState completableWorkState = CompletableWorkState.NOT_STARTED;

	public FmmCompletableNodeImpl(NodeId aNodeId) {
		super(aNodeId);
		// TODO Auto-generated constructor stub
	}

	public FmmCompletableNodeImpl(Class<? extends FmmCompletableNodeImpl> aCompletableClass, String anExistingNodeIdString) {
		super(NodeId.rehydrate(aCompletableClass, anExistingNodeIdString));
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean getAutocompletable() {
		return this.autocompletable;
	}

	@Override
	public void setAutoCompletable(short shortAutoCompletable) {
		this.autocompletable = shortAutoCompletable < 1 ? false : true;
	}

	@Override
	public void setAutoCompletable(boolean bAutocompletable) {
		this.autocompletable = bAutocompletable;
	}

	@Override
	public CompletionCommitmentType getCompletionCommitmentType() {  // wrapper
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getSequence() {
		return this.sequence;
	}

	@Override
	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	@Override
	public String getWorkStateCode() {
		return this.workStateCode;
	}

	@Override
	public void setCompletableWorkStateCode(String workStatusCode) {
		this.workStateCode = workStatusCode;
		this.completableWorkState = null;
	}

	@Override
	public CompletableWorkState getCompletableWorkState() {
		if(this.completableWorkState == null && this.getWorkStateCode() != null) {
			this.completableWorkState = CompletableWorkState.getObjectForName(this.getWorkStateCode());
		}
		return this.completableWorkState;
	}
	
	@Override
	public void setWorkState(CompletableWorkState aWorkState) {
		this.completableWorkState = aWorkState;
		this.workStateCode = aWorkState.getName();
	}

	@Override
	public boolean isGreen() {
		if(getCompletableWorkState().equals(CompletableWorkState.COMPLETE)) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isPink() {
		if(getCompletableWorkState().equals(CompletableWorkState.READY_FOR_REVIEW)) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isOrange() {
		if(getCompletableWorkState().equals(CompletableWorkState.ON_HOLD)) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isYellow() {
		if(getCompletableWorkState().equals(CompletableWorkState.STARTED)) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isGray() {
		if(getCompletableWorkState().equals(CompletableWorkState.NOT_STARTED)) {
			return true;
		}
		return false;
	}

	@Override
	public WorkStateColor getDecKanGlWorkStateColor() {
		if(isGray()) {
			return WorkStateColor.GRAY;
		} else if(isYellow()) {
				return WorkStateColor.YELLOW;
		} else if(isOrange()) {
				return WorkStateColor.ORANGE;
		} else if(isPink()) {
				return WorkStateColor.PINK;
		} else if(isGreen()) {
				return WorkStateColor.GREEN;
		}
		return null;
	}
	
	@Override
	public boolean isComplete() {
		return getCompletableWorkState() == CompletableWorkState.COMPLETE;
	}

	@Override
	public NounWorkStatus getNounWorkStatus() {
		return DecKanGlDictionary.getInstance().getNounWorkStatus(this.getClass().getSimpleName(), getCompletableWorkState());
	}

	@Override
	public int getNounWorkStatusGlyphResourceId() {
		return getNounWorkStatus().getBitmapResourceId();
	}

}
